package org.example.springbootdemo.mianshi.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 线程的几种实现方式
 */
public class Main {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //实现Runnable接口
        Thread thread1 = new Thread(new ThreadTesr01());
        thread1.start();

        //实现Callable接口
        Callable<String> myCallable = new ThreadTesr02();
        FutureTask<String> futureTask = new FutureTask<>(myCallable);
        Thread thread2 = new Thread(futureTask);
        thread2.start();
        String result = futureTask.get();
        System.out.println(result);

        //继承Thread类
        ThreadTesr03 thread3 = new ThreadTesr03();
        thread3.start();

        //使用匿名内部类
        Thread thread4 = new Thread(() -> {
            System.out.println("ThreadTesr03匿名内部类启动了");
        });

        //线程池
    }
}
